<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浏览器对象模型(Browser Object Model)</title>
    <style type="text/css">
        #tab {
            margin: 0px auto;
            width: 500px;
            height: 500px;

        }

        td {
            border: solid 2px red;
            width: 100px;
            height: 100px;
            text-align: center;
            font-weight: bold;
        }
    </style>
    <script>
        var times = 0;
        var st;
        function fn() {
            times++;
            console.log(times);
            for (let i = 1; i <= 42; i++) {
                var tdObj = document.getElementById('td' + i);
                tdObj.style.backgroundColor = 'white';
            }
            //获取1-9随机数
            var num = parseInt(Math.random() * 41 + 1);
            //获取对应的td对象
            var tdObj = document.getElementById('td' + num);
            //设置背景颜色
            tdObj.style.backgroundColor = 'red';
            if (times >= 30) {
                //将结果显示到span中
                document.getElementById('sp').innerText = '恭喜你，获得了:' + tdObj.innerText;
                clearInterval(st);
            }
        }
        function out() {
            //清空:初始化白色背景
            times = 0;
            for (let i = 1; i <= 42; i++) {
                var tdObj = document.getElementById('td' + i);
                tdObj.style.backgroundColor = 'white';
            }
            //抽奖开始，将span中的文本设置成：正在抽奖中...
            document.getElementById('sp').innerText = '正在抽奖中...'
            //设定定时器,3秒后出结果
            st = setInterval(fn, 100);
        }
    </script>
</head>

<body>
    <div id="btn" style="text-align: center; margin:10px">
        <button onclick="out()">点击抽奖</button>
        <span id="sp"></span>
    </div>
    <table id="tab">
        <table id="tab"> 
            <tr>
               <td id="td1">李韦峰</td>
               <td id="td2">卢国建</td>
               <td id="td3">郑玮喆</td>
               <td id="td4">庄云</td> 
               <td id="td5">廖治先</td>
               <td id="td6">郑文源</td>
               <td id="td7">戴俊锋</td>
               <td id="td8">陈昊童</td>
            </tr>  
            <tr>
               <td id="td9">谢金金</td>
               <td id="td10">占志新</td>
               <td id="td11">张淑芳</td>
               <td id="td12">刘永潘</td>
               <td id="td13">廖柏成</td>
               <td id="td14">郑宗帅</td>
               <td id="td15">吴欣燕</td>
               <td id="td16">陈梅香</td>
            </tr>
            <tr>
               <td id="td17">陈立智</td>
               <td id="td18">袁贵森</td>
               <td id="td19">赵浩敏</td>
               <td id="td20">林世涛</td>
               <td id="td21">罗启恒</td>
               <td id="td22">黄柱菘</td>
               <td id="td23">陈鹏</td>
               <td id="td24">张耀仁</td>
            </tr>
            <tr>
               <td id="td25">陈华伟</td>
               <td id="td26">张正豪</td>
               <td id="td27">韦仲晓</td>
               <td id="td28">黄富贵</td>
               <td id="td29">陆建锋</td>
               <td id="td30">曾德森</td>
               <td id="td31">吴文龙</td>
               <td id="td32">陆利群</td>
            </tr>
            <tr>
               <td id="td33">黄雄</td>
               <td id="td34">王世财</td>
               <td id="td35">张先杰</td>
               <td id="td36">胡基耀</td>
               <td id="td37">马鑫涛</td>
               <td id="td38">李涛</td>
               <td id="td39">杨凌翔</td>
               <td id="td40">罗此东</td>
               <td id="td41">唐皓颖</td>
               <td id="td42">白婉婷</td>
            </tr>
       
           </table> 
    </table>
    <!-- <script>
        //弹窗输入
        // window.prompt('请输入')
        //弹窗
        // window.alert('警告')

        //确认框:点击确认返回true， 取消返回false
        // var result = window.confirm('确定取消吗?');
        // if(result){
        //     alert('痛失600w');
        // }else{
        //     alert('成功躲过骗局');
        // }

        // 定时器:setTimeout():在设定的毫秒数后调用函数或计算表达式；

    </script> -->
</body>

</html>